﻿using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using SXFramWork.Core;
using SXFramWork.Model;
using SXFramWork.Service;

namespace SXFramWork.API.Controllers.Admin
{
    /// <summary>
    /// 角色管理
    /// </summary>
    public class SysRoleController : WebController
    {
        private readonly ISysRoleService _service;
        public SysRoleController(ISysRoleService sysRoleService)
        {
            _service = sysRoleService;
        }
        /// <summary>
        /// 角色列表
        /// </summary>
        /// <returns></returns>
        [Menu("角色管理")]
        [HttpGet]
        public async Task<IApiResult> List([FromQuery]RoleQueryModel model)
        {
            return await _service.Query(model);
        }
        /// <summary>
        /// 新增
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost]
        [Power("添加")]
        public async Task<IApiResult> Add([FromBody] RoleAddModel model)
        {
            return await _service.Add(model);
        }
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost]
        [Power("删除")]
        [Log]
        public async Task<IApiResult> Delete([FromBody]List<string> ids)
        {
            return await _service.Delete(ids);
        }
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost]
        [Power("更新")]
        public async Task<IApiResult> Update([FromBody]RoleUpdateModel model)
        {
            return await _service.Update(model);
        }
        /// <summary>
        /// 查询单个角色
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet]
        [Power("查询单个角色")]
        public async Task<IApiResult> Get([FromQuery] string id)
        {
            return await _service.GetById(id);
        }

    }
}